-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - Add reflect(skip_serializing)
which retains reflection but disables automatic serialization
#5250
Conversation
Bikeshed: I think I prefer |
reflect(ignore_serialization)
which retains reflection but disables automatic serializationreflect(do_not_serialize)
which retains reflection but disables automatic serialization
done! |
More bike shedding 😄: It's just a bit less to write and cleaner. But Edit: or use |
Hmm, I am against serde mentions since this might make people think (more than it does now) this applies serde's Right now this only disables automatic Edit: |
|
reflect(do_not_serialize)
which retains reflection but disables automatic serializationreflect(skip_serializing)
which retains reflection but disables automatic serialization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PROMETHIA-27 @MrGVSV can I get a second review here?
This probably needs to be rebased. @makspll would you be able to do that? |
I am currently on holiday, but can get on this ~monday |
95dc399
to
cf9b287
Compare
Aight, so I am working on this now, it's been a while so I'll take my time with this (and reflection changed a lot by the looks of it) but one thing I noticed so far: bevy_asset::asset_server: encountered an error while loading an asset: No registration found for `glam::vec3::Vec3` Now I can't remember if that was there before, probably was but I didn't notice, what I think is happening is that because of the way glam imports changed, the type names are now platform dependent, meaning that on my machine the type name this is saved under is now: I've squashed all the commits for ease of re-basing, apologies for the force push |
Yep this is a known issue and we're trying to fix it via #5805. |
Okay that's fantastic, I remember bumping into that problem earlier with scripting but it completely fell out my head |
One question @MrGVSV, are enum variants supposed to be ignorable by reflection/serialization ? If so, how would the serialziation/deserialization of ignored variants look like? |
I added it as an option. I don't know what specific use-cases it has, though. My original thought was that it would allow for enums to contain variants meant for runtime data and variants meant for serialized data, such as If you find that it's not necessary or should be removed, feel free to make an issue for it, though! I have no problem removing it if it isn't useful haha |
Hmm I see, Yeah I definitely see possible uses for it so removing is not what I want to do. I am wondering however if the current First bit of serialization: let variant_type = self.enum_value.variant_type(); // crash here on ignored variants
let variant_name = self.enum_value.variant_name(); First bit of deserialization: let key = map.next_key::<String>()?;
match key.as_deref() {
Some(type_fields::VARIANT) => {}
Some(key) => return Err(V::Error::unknown_field(key, &[type_fields::VARIANT])),
_ => {
return Err(V::Error::missing_field(type_fields::VARIANT));
}
} Relevant macro code on main: for variant in reflect_enum.active_variants() {
let ident = &variant.data.ident;
let name = ident.to_string();
let unit = reflect_enum.get_unit(ident);
// ... more code ...
let mut add_fields_branch = |variant, info_type, arguments, field_len| {
// .. more code ..
// note this code doesn't run for ignored variants
enum_field_len.push(quote! {
#unit{..} => #field_len
});
enum_variant_name.push(quote! {
#unit{..} => #name
});
enum_variant_type.push(quote! {
#unit{..} => #bevy_reflect_path::VariantType::#variant
});
}; |
Oh great catch! Yeah, it's a bit weird because methods like
While I see the possible usefulness of ignoring variants, perhaps it's better to just go with Option 3 and remove this functionality altogether (at least for the time being). Option 1 isn't awful but I think it will have a breadth that basically matches Option 3. Option 2 just hurts ergonomics imo. I think it will be better to remove this as it's a really exposed footgun (oversight on my part). We can always add it back in, and it would be better to remove it now before 0.9 releases with it (forcing a possible future removal to be a breaking change). I'll make an issue for this unless there's any pushback. |
@MrGVSV yeah okay, I haven't touched much code in a month so I assumed I was tripping :P Alright well, In that case I am in favour of removing the variant ignore behaviour for now on the basis of what's already been said + the fact that adding it complicates this PR a bit: without variant serialization, I can represent "Serialization Ignoring Behaviour" with a set of field indices, with variants I now need an Enum, with either that or a set of strings for variant names. Keeping just index sets is probably more performant and ergonomic, since the serialization process is just: for (idx,field) in my_thing.iter_fields().enumerate(){
if !ignored.contains(idx){
// serialize
}
} |
…akspll/bevy into no-serialize-attribute-reflect
Alright so that should be it then, I've removed the variant ignoring mechanisms, and re-based everything, should be ready for review |
Alrighty, that should be @MrGVSV's review implemented, biggest change is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few more comments
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
…akspll/bevy into no-serialize-attribute-reflect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Fantastic, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now! Those dead_code annotations are surprising to me, but they do seem to be needed.
bors r+ |
… automatic serialization (#5250) # Objective - To address problems outlined in #5245 ## Solution - Introduce `reflect(skip_serializing)` on top of `reflect(ignore)` which disables automatic serialisation to scenes, but does not disable reflection of the field. --- ## Changelog - Adds: - `bevy_reflect::serde::type_data` module - `ReflectSerializableWithData` trait for retrieving `SerializationData` which is implemented via macros - `SerializationData` structure for describing which fields are to be/not to be ignored - the `skip_serialization` flag for `#[reflect(...)]` - Removes: - ability to ignore Enum variants in serialization, since that didn't work anyway ## Migration Guide - Change `#[reflect(ignore)]` to `#[reflect(skip_serializing)]` where disabling reflection is not the intended effect. - Remove ignore/skip attributes from enum variants as these won't do anything anymore
Build failed (retrying...): |
… automatic serialization (#5250) # Objective - To address problems outlined in #5245 ## Solution - Introduce `reflect(skip_serializing)` on top of `reflect(ignore)` which disables automatic serialisation to scenes, but does not disable reflection of the field. --- ## Changelog - Adds: - `bevy_reflect::serde::type_data` module - `SerializationData` structure for describing which fields are to be/not to be ignored, automatically registers as type_data for struct-based types - the `skip_serialization` flag for `#[reflect(...)]` - Removes: - ability to ignore Enum variants in serialization, since that didn't work anyway ## Migration Guide - Change `#[reflect(ignore)]` to `#[reflect(skip_serializing)]` where disabling reflection is not the intended effect. - Remove ignore/skip attributes from enum variants as these won't do anything anymore
Pull request successfully merged into main. Build succeeded: |
reflect(skip_serializing)
which retains reflection but disables automatic serializationreflect(skip_serializing)
which retains reflection but disables automatic serialization
… automatic serialization (bevyengine#5250) # Objective - To address problems outlined in bevyengine#5245 ## Solution - Introduce `reflect(skip_serializing)` on top of `reflect(ignore)` which disables automatic serialisation to scenes, but does not disable reflection of the field. --- ## Changelog - Adds: - `bevy_reflect::serde::type_data` module - `SerializationData` structure for describing which fields are to be/not to be ignored, automatically registers as type_data for struct-based types - the `skip_serialization` flag for `#[reflect(...)]` - Removes: - ability to ignore Enum variants in serialization, since that didn't work anyway ## Migration Guide - Change `#[reflect(ignore)]` to `#[reflect(skip_serializing)]` where disabling reflection is not the intended effect. - Remove ignore/skip attributes from enum variants as these won't do anything anymore
… automatic serialization (bevyengine#5250) # Objective - To address problems outlined in bevyengine#5245 ## Solution - Introduce `reflect(skip_serializing)` on top of `reflect(ignore)` which disables automatic serialisation to scenes, but does not disable reflection of the field. --- ## Changelog - Adds: - `bevy_reflect::serde::type_data` module - `SerializationData` structure for describing which fields are to be/not to be ignored, automatically registers as type_data for struct-based types - the `skip_serialization` flag for `#[reflect(...)]` - Removes: - ability to ignore Enum variants in serialization, since that didn't work anyway ## Migration Guide - Change `#[reflect(ignore)]` to `#[reflect(skip_serializing)]` where disabling reflection is not the intended effect. - Remove ignore/skip attributes from enum variants as these won't do anything anymore
… automatic serialization (bevyengine#5250) # Objective - To address problems outlined in bevyengine#5245 ## Solution - Introduce `reflect(skip_serializing)` on top of `reflect(ignore)` which disables automatic serialisation to scenes, but does not disable reflection of the field. --- ## Changelog - Adds: - `bevy_reflect::serde::type_data` module - `SerializationData` structure for describing which fields are to be/not to be ignored, automatically registers as type_data for struct-based types - the `skip_serialization` flag for `#[reflect(...)]` - Removes: - ability to ignore Enum variants in serialization, since that didn't work anyway ## Migration Guide - Change `#[reflect(ignore)]` to `#[reflect(skip_serializing)]` where disabling reflection is not the intended effect. - Remove ignore/skip attributes from enum variants as these won't do anything anymore
Objective
Solution
reflect(skip_serializing)
on top ofreflect(ignore)
which disables automatic serialisation to scenes, but does not disable reflection of the field.Changelog
bevy_reflect::serde::type_data
moduleSerializationData
structure for describing which fields are to be/not to be ignored, automatically registers as type_data for struct-based typesskip_serialization
flag for#[reflect(...)]
Migration Guide
#[reflect(ignore)]
to#[reflect(skip_serializing)]
where disabling reflection is not the intended effect.